import { PluginFunction, VueConstructor, default as VueImport } from 'vue';
import { VueDelegate } from './controllers/vue-delegate';
import { appInitialize } from './app-initialize';
import { installDelegate } from '@ibiz/model-location';

let Vue: typeof VueImport;

export const install: PluginFunction<any> = (_Vue: VueConstructor, config: any) => {
  if (Vue && _Vue === Vue) {
    if (process.env.NODE_ENV !== 'production') {
      console.error('[Ionic] already installed. Vue.use(Ionic) should be called only once.');
    }
    return;
  }
  Vue = _Vue;
  Vue.config.ignoredElements.push(/^qx-/);

  appInitialize(config);

  const delegate = new VueDelegate(Vue);
  installDelegate(delegate);
};
